using System;
using UnityEngine;

namespace EventBehaviorTree
{
    [Serializable]
    public abstract class EventNode
    {
        protected string _key;
        /// <summary>
        /// Use function SetKey() to avoid misuse of this parameter.
        /// </summary>
        public string Key { get => _key; protected set => _key = value; }
        protected bool _isWorking;
        /// <summary>
        /// Send message to the senior node.
        /// </summary>
        protected Action<NodeMsg> SuperiorNodeEvent;
        public EventNode() { _isWorking = false; }
        public virtual void SetKey(string key = "NODE") { Key = key; }
        public abstract void SetCoroutineStarter(MonoBehaviour coroutineStarter);
        /// <summary>
        /// As message sender to the senior node.
        /// </summary>
        /// <param name="seniorNodeEvent">parent node event</param>
        public void SetReceiver(Action<NodeMsg> seniorNodeEvent) { SuperiorNodeEvent = seniorNodeEvent; }
        /// <summary>
        /// Do task or get the message from one sub node.
        /// </summary>
        /// <param name="nodeMessage"></param>
        public abstract void NodeEvent(NodeMsg nodeMessage);
    }
}
